package org.kgc.alanhealth.controller;

import org.kgc.alanhealth.entity.HospitalDrugs;
import org.kgc.alanhealth.entity.HospitalSymptom;
import org.kgc.alanhealth.entity.HospitalSymptomatic;
import org.kgc.alanhealth.service.DrugStoreService;
import org.kgc.alanhealth.util.Result;
import org.kgc.alanhealth.vo.HospitalDrugsDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("store")
@CrossOrigin(origins = "*")
public class DrugStoreController {
    @Autowired
    DrugStoreService drugStoreService;

    @RequestMapping("query")
    public Result getAllDrugs(Integer currentPageNo,Integer pageSize){
        List<HospitalDrugsDetail> list=drugStoreService.getAllDrugs(currentPageNo,pageSize);
        if (list!=null&&!list.isEmpty()){
            return Result.success(list);
        }else{
            return Result.error("没有找到数据");
        }
    }
    @RequestMapping("querycount")
    public Result getAllDrugsCount(){
        int list=drugStoreService.getAllByDrugsCount();
        if (list!=0){
            return Result.success(list);
        }else{
            return Result.error("没有找到数据");
        }
    }
    @RequestMapping("query1")
    public Result getDrug(int id){
        List<HospitalDrugsDetail> drugs=drugStoreService.getDrugById(id);
        if (drugs!=null){
            return Result.success(drugs);
        }else{
            return Result.error("没有找到数据");
        }
    }
    @RequestMapping("querybycondition")
    public Result getDrug(String keyword){
        List<HospitalDrugsDetail> drugs=drugStoreService.getDrugByCondition(keyword);
        if (drugs!=null){
            return Result.success(drugs);
        }else{
            return Result.error("没有找到数据");
        }
    }
    @RequestMapping("query2")
    public Result getAllSymptomatic(){
        List<HospitalSymptomatic> list =drugStoreService.getAllSymptomatic();
        if (list!=null&&!list.isEmpty()){
            return Result.success(list);
        }else {
            return Result.error("没有找到数据");
        }
    }
    @RequestMapping("query3")
    public Result getAllSymptom(int id){
        List<HospitalSymptom> list =drugStoreService.getAllSymptomById(id);
        if (list!=null&&!list.isEmpty()){
            return Result.success(list);
        }else {
            return Result.error("没有找到数据");
        }
    }
}
